package com.xayy.mgt.enums;

import lombok.Getter;

@Getter
public enum ResultItemEnum {
    SUCCESS(1, "成功"),

    FAIL(0, "失败");

    private Integer code;
    private String name;

    ResultItemEnum(Integer code, String name) {
        this.name = name;
        this.code = code;
    }

    public static String valueof(Integer index) {
        for (ResultItemEnum resultItemEnum : values()) {
            if (resultItemEnum.getCode() == index) {
                return resultItemEnum.name;
            }
        }
        return "";
    }

    public static Integer valueof(String name) {
        for (ResultItemEnum resultItemEnum : values()) {
            if ( name.equals(resultItemEnum.name())) {
                return resultItemEnum.code;
            }
        }
        return null;
    }
}
